package com.sf.rbac.web.advice;

import com.sf.rbac.ex.BusinessException;
import com.sf.rbac.util.JsonResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class CommonControllerAdvice {

    /**
     * 可以处理对应类型异常
     */

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public JsonResult handler(Exception e){
        e.printStackTrace();
        return JsonResult.fail();
    }
    /**
     * 出现自己业务层的异常
     */
    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public JsonResult handler(BusinessException e){
        return JsonResult.fail(e.getMessage(),null);
    }

}
